<template>
	<view>
		<image style="height: 100vh;width: 100%;"
			:src="vk.vuex.get('$app.appinfo.mfld_image')" @click="fangdou">
		</image>
		<!-- <button type="primary" @click="freeReceive" >免费领取</button> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		onShow() {
			//检查登录情况，没注册自动用openid注册，注册过的直接登录
			vk.userCenter.loginByWeixin({
				loading: false,
				data: {
					appid: vk.vuex.get('$app.appid'),
					appsecret: "",
					type: ""
				},
				success: (data) => {
					// 登陆成功后才能执行此云函数
					this.userInfo = data.userInfo;
				}
			});
		},
		methods: {
			fangdou() {
				vk.pubfn.throttle(() => {
					this.freeReceive()
				}, 5000);
			},
			freeReceive() {
				vk.callFunction({
					url: 'client/user/kh/freeReceive',
					title: '请求中...',
					data: {
						appid: vk.vuex.get('$app.appid'),
					},
					success: (data) => {
						console.log("data=", data);
						if (data.state == -1) {
							uni.showModal({
								title: "领取失败",
								content: data.tips,
								showCancel: false,
								confirmText: "确认",
								success: function(res) {
									if (res.confirm) {
										uni.redirectTo({
											url: "/pages_sub/moreRecords/moreRecords"
										})
									}
								}
							})
						} else {
							uni.showModal({
								content: data.bean + "金豆领取成功",
								showCancel: false,
								confirmText: "确认",
								success: function(res) {
									if (res.confirm) {
										uni.redirectTo({
											url: "/pages_sub/moreRecords/moreRecords"
										})
									}
								}
							})
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>